package com.etpjava.action;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.etpjava.model.InviteJob;
import com.etpjava.service.InviteJobService;
import com.etpjava.service.impl.InviteJobServiceImpl;
import com.etpjava.util.GetSth;
import com.etpjava.util.Page;
import com.opensymphony.xwork2.ActionSupport;



public class InviteJobAction extends ActionSupport {

/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	//	private List<InviteJob> invites;
	static Log logger = LogFactory.getLog(InviteJobAction.class);
	 private int page=1;
	 private Page pagelist;
	 private String name;
	 private Integer age;
	 private Integer id;
	 private Date birthday;
	 private String education;
	 private String experience;
	 private String position;
	 private String profession;
	 private String isEmploied;
	 private int telphone;
	 private InviteJob inviteJob;
	 private List<InviteJob> invites; 
	 private int[] ids;//����
	 InviteJobService invite=new InviteJobServiceImpl();
	 
	 public String findByBirth(){
		 
		 logger.info("����:"+birthday);
		 if(pagelist==null){
			 pagelist=new Page(1);
		 }
		 String birth;
		 pagelist.setActionname("findByBirth");
		 if(birthday!=null){
		 birth=GetSth.fDate(birthday, "yyyy-MM-dd");
		 
		 logger.info(birth);
		 }else{
		    birth="1970-01-01";
		 
	       logger.info("gg"+birth);
		 }
		 invite.findByBirth(pagelist, birth);
		 
//		 this.pager=invite.findByBirth(birth,page);
		 return "list";
	 }

	public String findFuzzy()throws Exception{
		Map<String,String> sw=new HashMap<String,String>();
		if(pagelist==null){
			pagelist=new Page(1);
		}
		pagelist.setActionname("findFuzzy");
		logger.info("ffff"+age);
		if(age!=null){
		String birth=GetSth.getDate(age);
		logger.info("���䣺"+birth);
		
		
		sw.put("birth",birth);
		}
		logger.info("����:"+GetSth.change(name));
	    sw.put("name",GetSth.change(name));
		sw.put("profession", GetSth.change(profession));
	    sw.put("education", GetSth.change(education));
	    invite.findFuzzyForPage(pagelist,sw);
//		this.pager=invite.findFuzzyForPage(sw,page);
		return "list";
	  }
	 /**
	  * @ ����δ¼ȡ��
	 * @return
	 */
	public String NoEmploy(){
		 if(pagelist==null){
			 pagelist=new Page(1);
		 }
		 pagelist.setActionname("NoEmploy");
		 invite.findByEmployNoForPage(pagelist);
//		 this.pager=invite.findByEmployNoForPage(page);
		 return "list";
	 }
	 
//	 /**
//	  * @ ����¼ȡ��
//	 * @return
//	 */
//	public String IsEmploy(){
//		 this.pager=invite.findByEmployYesForPage(page);
//		 return "list";
//	 }
	 /**
	  * @ ɾ�����¼
	 * @return
	 */
	public String delete(){ //ɾ�����¼
		 inviteJob=invite.findById(id);
		 invite.delete(inviteJob);
		 return "delete";
	 }
	
	 /**
	  *@����ɾ���¼
	 * @return
	 */
	public String deletese() {//����ɾ���¼
			if (ids!=null&&ids.length!=0) {
				for (int id :ids) {
					invite.delete(id);
				}
			}
		  return "list";
		}
	 /**
	  * @��������ҳ����
	 * @return
	 * @throws Exception
	 */
	public String findByAge()throws Exception{
		if(pagelist==null){
			pagelist=new Page(1);
		}
		
	    String birth=GetSth.getDate(age);
		pagelist.setActionname("findByAge");
		invite.findByAgeForPage(pagelist, birth);
//		 this.pager=invite.findByAgeForPage(birth,page);
		 
//		 this.addFieldError("my", "dsaf");
		 return "list";
		 
	 }
	 
	 /**
	  * @��ݽ���̶ȷ�ҳ����
	 * @return ����Pager
	 * @throws Exception
	 */
	public String findByEducation()throws Exception{
		if(pagelist==null){
			pagelist=new Page(1);
		}
		invite.findEducationForPage(pagelist, GetSth.change(education));
//		 this.pager=invite.findEducationForPage(education, page);
		 return "list";
		 
	 }
	
	 /**
	  * @��ݹ��������ҳ����
	 * @return
	 * @throws Exception
	 */
	public String findByExperience()throws Exception{
		if(pagelist==null){
			pagelist=new Page(1);
		}
		pagelist.setActionname("findByExperience");
		invite.findExperienceForPage(pagelist, GetSth.change(experience));
//         this.pager=invite.findExperienceForPage(experience, page);
		logger.info(pagelist.getActionname());
		logger.info(pagelist.getPageTotalCount());
		logger.info(pagelist.getPageNums().length);
		 return "list";
		 
	 }
	
	 /**
	  * @ ���ID������ϸ��¼
	 * @return
	 * @throws Exception
	 */
	public String findById()throws Exception{
		  inviteJob=invite.findById(id);
	      return "findbyId";
	 }
	
	 /**
	  *@param ���ְҵ���з�ҳ��ѯ
	 * @return ֱ�ӷ�����ҳ��
	 * @throws Exception
	 */
	public String findByProfession()throws Exception{
//         this.pager=invite.findProfessionForPage(profession,page);
		if(pagelist==null){
			pagelist=new Page(1);
		}
		pagelist.setActionname("findByProfession");
		invite.findProfessionForPage(pagelist, GetSth.change(profession));
		 return "list";
		 
	 }
	
     /**
      * @param ��ҳ��ѯ���е���Ƹ��¼
     * @return
     * @throws Exception
     */
    public String ShowAll()throws Exception{
	     if(pagelist==null){
	    	 pagelist=new Page(1);
	     }
	     pagelist.setActionname("ShowAll");
	     logger.info(pagelist.getActionname());
	     invite.queryForPage(pagelist);
	     logger.info(pagelist.getPageNums());
	     logger.info(pagelist.getRowTotalCount());
	     logger.info(pagelist.getList().get(0));
	     logger.info(pagelist.getActionname());
	  
	 	 return "list";
	 
 }
	
	/**
	 * @param ��Ӻ��޸���Ƹ��Ϣ��id���������޸ĵ��жϲ���
	 * @return
	 * @throws Exception
	 */
	public String saveInvite()throws Exception{
		 if(null==id){
			 inviteJob.setRegistTime(new Date());
			 invite.add(inviteJob);
			 
		 }else{
			 invite.modify(inviteJob);
		 }
		 return "fresh";
	 }

	
	 public String getEducation() {
		return education;
	}
	 public String getExperience() {
		return experience;
	}
	 public InviteJob getInviteJob() {
		return inviteJob;
	}

	public List<InviteJob> getInvites() {
		return invites;
	}
	public String getName() {
		return name;
	}
	public String getPosition() {
		return position;
	}

	public String getProfession() {
		return profession;
	}
	public int getTelphone() {
		return telphone;
	}
	public String isEmploied() {
		return isEmploied;
	}
	

	public void setEducation(String education) {
		this.education = education;
	}
	public void setEmploied(String isEmploied) {
		this.isEmploied = isEmploied;
	}
	public void setExperience(String experience) {
		this.experience = experience;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public void setInviteJob(InviteJob inviteJob) {
		this.inviteJob = inviteJob;
	}
	public void setInvites(List<InviteJob> invites) {
		this.invites = invites;
	}
	public void setName(String name) {
		this.name = name;
	}
	public void setPosition(String position) {
		this.position = position;
	}
	public void setProfession(String profession) {
		this.profession = profession;
	}
	public void setTelphone(int telphone) {
		this.telphone = telphone;
	}
	
	public Integer getId() {
		return id;
	}
	public String getIsEmploied() {
		return isEmploied;
	}
	
	public void setIsEmploied(String isEmploied) {
		this.isEmploied = isEmploied;
	}
	
	public void setIds(int[] ids) {
		this.ids = ids;
	}

	public int getPage() {
		return page;
	}

	
	public void setPage(int page) {
		this.page = page;
	}

	

	public int[] getIds() {
		return ids;
	}
	public Date getBirthday() {
		return birthday;
	}
	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public Page getPagelist() {
		return pagelist;
	}

	public void setPagelist(Page pagelist) {
		this.pagelist = pagelist;
	}

	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}


	
}
